﻿using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace BestPracticesParts.StringProvider
{
    [ToolboxItemAttribute(false)]
    public class StringProvider : WebPart, IStringConnection
    {
        private TextBox theString;

        [ConnectionProvider("String Provider")]
        public IStringConnection ConnectionInterface()
        {
            return this;
        }

        public string ProvidedString
        {
            get { return theString.Text; }
        }

        protected override void CreateChildControls()
        {
            theString = new TextBox();
            if (!Page.IsPostBack)
                theString.Text = "Web Part connections are good";
            this.Controls.Add(theString);
        }

        protected override void RenderContents(HtmlTextWriter writer)
        {
            writer.Write("<p>Enter a string</p>");
            theString.RenderControl(writer);

        }
    }

}
